﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using Empresa.Sistema.Datos.Entidades;
using Empresa.Sistema.Aplicacion;

namespace Empresa.Sistema.Presentacion
{
    public partial class mntPersonas : Form
    {
        
        #region "Instanciar"

        private static mntPersonas m_FormDefInstance;
        public static mntPersonas DefInstance
        {
            get
            {
                if (m_FormDefInstance == null || m_FormDefInstance.IsDisposed)
                    m_FormDefInstance = new mntPersonas();
                return m_FormDefInstance;
            }
            set
            {
                m_FormDefInstance = value;
            }
        }

        #endregion 
        
        public mntPersonas()
        {
            InitializeComponent();
        }

        List<Persona> lista = new List<Persona>();
        public Persona per;
        public string accion;

        private void btnEliminar_Click(object sender, EventArgs e)
        {
            accion = "eliminar";
            var regPersona = new regPersonas();
            regPersona.Owner = this;
            regPersona.ShowDialog(); 
        }

        private void btnModificar_Click(object sender, EventArgs e)
        {
            accion = "modificar";
            var regPersona = new regPersonas();
            regPersona.Owner = this;
            regPersona.ShowDialog();
        }

        private void btnAgregar_Click(object sender, EventArgs e)
        {
            accion = "adicionar";
            var regPersona = new regPersonas();
            regPersona.Owner = this;
            regPersona.ShowDialog();
        }

        private void mntPersonas_Load(object sender, EventArgs e)
        {
            lista = new Personas().Listar();
            dgvPersonas.AutoGenerateColumns = false;
            dgvPersonas.DataSource = lista;
        }

        private void txtApellido_TextChanged(object sender, EventArgs e)
        {
            lista = new Personas().ConsultaPorApellido(txtApellido.Text);
            dgvPersonas.AutoGenerateColumns = false;
            dgvPersonas.DataSource = lista;
        }

        private void dgvPersonas_SelectionChanged(object sender, EventArgs e)
        {
            if (dgvPersonas.CurrentCell.RowIndex >= 0)
            {
                per = (Persona)lista[dgvPersonas.CurrentCell.RowIndex];
            }
        }

        



    }
}
